#include <stdlib.h>
#include <stdio.h>
#include <nds.h>

#include "common.h"

#include "interrupts.h"

int te=192;

void DrawGLScene() {
	glLoadIdentity();
	glPolyFmt(POLY_ALPHA(15) | POLY_CULL_NONE);

	#define mytov16(n) ((n) << 6)
	#define myglVertex2int(x, y, z) glVertex3v16(mytov16(x), mytov16(191-(y)), floattov16(z))

	glBegin(GL_QUADS);
		glColor3f(1.0f,0.5f,0.4f);
		myglVertex2int(0, te, -1.0f);

		glColor3f(0.0f,0.5f,0.4f);
		myglVertex2int(256, te, -1.0f);

		glColor3f(1.0f,0.5f,0.4f);
		myglVertex2int(256, 0, -1.0f);

		glColor3f(0.0f,0.5f,0.4f);
		myglVertex2int(0, 0, -1.0f);
	glEnd();

	glBegin(GL_TRIANGLES);
		glColor3f(1.0f,0.0f,0.0f);
		myglVertex2int(30, 100, -1.0f);

		glColor3f(1.0f,1.0f,0.0f);
		myglVertex2int(30, 50, -1.0f);

		glColor3f(.0f,0.0f,1.0f);
		myglVertex2int(100, 10, -1.0f);
	glEnd();
}

void VblHandler() {
	scanKeys();

#if 0
	if(keysHeld() & KEY_Y) te++;
	if(keysHeld() & KEY_X) te--;

	DrawGLScene();

	glFlush(0);
#endif
}

inline void interruptsInit() {
	irqSet(IRQ_VBLANK, VblHandler);
}

